
package com.shop.cereshop.admin.controller.recommend;

import com.shop.cereshop.admin.page.recommend.CereRecommendCommentPage;
import com.shop.cereshop.admin.param.recommend.RecommendStatusPageParam;
import com.shop.cereshop.admin.param.recommend.RecommendTrendsParam;
import com.shop.cereshop.admin.service.history.CereWebHistoryService;
import com.shop.cereshop.admin.service.recommend.CereRecommendCommentService;
import com.shop.cereshop.commons.domain.common.Page;
import com.shop.cereshop.commons.domain.recommend.CereRecommendComment;
import com.shop.cereshop.commons.domain.user.CerePlatformUser;
import com.shop.cereshop.commons.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


/**
 * <p>
 * 前端控制器
 * @用户表
 * </p>
 *
 * @author 罗霄
 * @date 2025-08-25
 */
@Slf4j
@RestController
@RequestMapping("/recommendUser")
@Api(value = "RecommendAtUser", tags = "动态圈评论管理")
public class RecommendTrendsController {
    @Autowired
    private CereRecommendCommentService recommendCommentService;

    @Autowired
    private CereWebHistoryService cereWebHistoryService;

    @DeleteMapping("/delete/report")
    @ApiOperation(value = "删除动态圈评论")
    public Result delete(@RequestParam("commentId") Long commentId, HttpServletRequest request) {
            String action ="";
            String result="";
            CerePlatformUser user  =(CerePlatformUser)request.getAttribute("user");
        Integer number = recommendCommentService.deleteRecommendComment(commentId,request);
        if (number>0){
            result="成功";
        }else {
            result="失败";
        }
        action = user.getName()+"删除了动态圈评论id为"+commentId+"的动态圈评论";
        cereWebHistoryService.addHistory(user.getPlatformUserId(),user.getName(),user.getPhone(),user.getAvatar()==null ?null:user.getAvatar(),action,result,2);

        return Result.success(result);
    }

    @PostMapping("/update/statue")
    @ApiOperation(value = "修改动态圈评论是隐藏还是显示")
    public Result updateStatue(@RequestBody RecommendStatusPageParam param, HttpServletRequest request) {
        String action ="";
        String result="";
      CerePlatformUser user  =(CerePlatformUser)request.getAttribute("user");
        Integer number = recommendCommentService.updateStatue(param,request);
        if (number>0){
            result="成功";
        }else {
            result="失败";
        }
        if (param.getStatus()==1){
            action=user.getName()+"屏蔽了"+"动态圈评论id为"+param.getRecommendCommentId()+"的动态圈评论";
        }else if (param.getStatus()==0){
           action = user.getName()+"展示"+"动态圈评论id为"+param.getRecommendCommentId()+"的动态圈评论";
        }
        cereWebHistoryService.addHistory(user.getPlatformUserId(),user.getName(),user.getPhone(),user.getAvatar()==null ?null:user.getAvatar(),action,result,1);

        return Result.success(number);
    }

    @PostMapping("/getAll")
    @ApiOperation(value = "动态圈评论列表查询")
    public Result<Page<CereRecommendComment>> getAll(@RequestBody RecommendTrendsParam param,HttpServletRequest request) {
        Page result =recommendCommentService.getAll(param,request);
        return Result.success(result);
    }





}
